package com.pan.file.impl;

import com.pan.file.CreateFile;
import com.pan.utils.TemplateReader;
import com.pan.utils.UmlConfig;

import java.io.*;
import java.nio.Buffer;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CreateXmlFile implements CreateFile {


    private String template;
    {
        template = TemplateReader.INSTANCE.readPicture();
    }

    @Override
    public void save(List<String> contentList, String fileName) {
        String content = contentList.stream().reduce((x, y) -> x + "\n" + y).get();
        File saveFile = new File(UmlConfig.INSTANCE.getSaveDirPath()+"/"+fileName+".xml");
        try {
            BufferedWriter writer  = new BufferedWriter(new FileWriter(saveFile));
            writer.write(template.replaceAll("#\\{value\\}",content));
            writer.flush();
            writer.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
